package com.thkj.modules.user.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.abel533.entity.Example;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.thkj.modules.dao.BusinWorkerMapper;
import com.thkj.modules.user.entity.BusinWorker;
import com.thkj.modules.user.service.BusinWorkerService;

import dp.dao.PagingList;
import dp.service.BaseService;

@Service
public class BusinWorkerServiceImpl extends BaseService implements BusinWorkerService {

    @Autowired
    private BusinWorkerMapper businWorkerMapper;

    @Override
    public void insert(BusinWorker businWorker) {
        businWorkerMapper.insert(businWorker);
    }

    @Override
    public PagingList<BusinWorker> query(Integer page,
                                         Integer size,
                                         String individual_id) {
        if (StringUtils.isBlank(individual_id)) {
            return new PagingList<>(0, null, 0, 0, 0);
        }
        if (page != null && size != null) {
            PageHelper.startPage(page, size);
        } else {
            PageHelper.startPage(1, 0);
        }
        Example example = new Example(BusinWorker.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("individualId", individual_id);

        example.setOrderByClause("entryTime DESC");

        List<BusinWorker> violations = businWorkerMapper.selectByExample(example);
        PageInfo<BusinWorker> pageInfo = new PageInfo<>(violations);
        return new PagingList(pageInfo.getTotal(), pageInfo.getList(), pageInfo.getPages(), pageInfo.getPageNum(), pageInfo.getPageSize());
    }

    @Override
    public List<Map> queryByIndividualId(String individual_id, String timeStr) {
        return businWorkerMapper.queryByIndividualId(individual_id,timeStr);
    }

}